package com.taiji.dicom4cloud.common.core.utils;

import cn.hutool.core.lang.UUID;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 * @Description
 * @Author fanxl
 * @Date 2021/5/20
 **/
public class CommonUtils {

    /**
     * 获取UUID
     *
     * @return
     */
    public static String getUUID(){
        return UUID.fastUUID().toString().replace("-","");
    }

    /**
     * 数组转short
     * @param bytes
     * @return
     */
    public static short bytesToShort(byte[] bytes) {
        return ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN).getShort();
    }

    /**
     * 字节数组到float的转换.
     */
    public static float getFloat(byte[] b) {
        // 4 bytes
        int accum = 0;
        for ( int shiftBy = 0; shiftBy < 4; shiftBy++ ) {
            accum |= (b[shiftBy] & 0xff) << shiftBy * 8;
        }
        return Float.intBitsToFloat(accum);
    }
}
